package org.budo.netty.servlet.server.handler.servlet.config;

import java.util.Collections;
import java.util.Enumeration;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletRegistration;

import org.budo.netty.servlet.server.handler.servlet.registration.BudoServletRegistration;

/**
 * @author lmw
 */
public class BudoServletConfig implements ServletConfig {
    private ServletRegistration servletRegistration;

    public BudoServletConfig(ServletRegistration servletRegistration) {
        this.servletRegistration = servletRegistration;
    }

    @Override
    public Enumeration<String> getInitParameterNames() {
        return Collections.enumeration(this.servletRegistration.getInitParameters().keySet());
    }

    @Override
    public String getInitParameter(String name) {
        return this.servletRegistration.getInitParameter(name);
    }

    @Override
    public ServletContext getServletContext() {
        return ((BudoServletRegistration) this.servletRegistration).getServletContext();
    }

    @Override
    public String getServletName() {
        return this.servletRegistration.getName();
    }

    @Override
    public String toString() {
        return super.toString() //
                + ", servletName=" + this.getServletName() //
                + ", servletContext=" + this.getServletContext();
    }
}
